Skip to content

Reproducing Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the Intensive Care Unit#1021

Open
meduk2 wants to merge 25 commits intosunlabuiuc:masterfrom
meduk2:tpc_los_replication
Open

Reproducing Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the Intensive Care Unit#1021
meduk2 wants to merge 25 commits intosunlabuiuc:masterfrom
meduk2:tpc_los_replication

Conversation

@meduk2
Copy link
Copy Markdown

@meduk2 meduk2 commented Apr 19, 2026

This PR reproduces the Temporal Pointwise Convolution (TPC) model and introduces a new hourly ICU length-of-stay prediction task in PyHealth.

All implementation, tests, and example pipelines are included. The contribution follows PyHealth BaseModel and task conventions and includes fast synthetic tests for reproducibility.

Primary files:

  • pyhealth/models/tpc.py
  • pyhealth/tasks/hourly_los.py
  • examples/*
  • tests/*
  • docs/api/*

CS598 Deep Learning for Healthcare Project

This PR reproduces and contributes an implementation of:

Temporal Pointwise Convolutional Networks for Length of Stay Prediction in the Intensive Care Unit
Rocheteau et al., ACM CHIL 2021

Paper: https://arxiv.org/abs/2007.09483

Contributors

  • Michael Edukonis (meduk2@illinois.edu)
  • Keon Young Lee (kylee7@illinois.edu)
  • Tanmay Thareja (tanmayt3@illinois.edu)

PR Overview

Contribution Types

This PR includes:

  • Model contribution
  • Standalone Task contribution
  • Synthetic data tests
  • End to End Pipeline (Model + Task + Dataset configs) example scripts + combined dual dataset run

Problem Overview

Efficient ICU bed management depends critically on estimating how long a patient will remain in the ICU.

This is formulated as:

•	Input: Patient data up to hour _t_
•	Output: Remaining ICU length of stay _(LoS)_ at time _t_

We follow the formulation in the original paper, predicting remaining LoS at each hour of the ICU stay.

Implementation Details

1) Model Contribution

pyhealth.models.tpc

We implement the Temporal Pointwise Convolution (TPC) model as a PyHealth-compatible model by extending BaseModel and follows the original paper’s architecture with adaptations for PyHealth’s input/output interfaces. Index files were updated to include the new modules accordingly.

2) Task Contribution

We implement a custom PyHealth task: Hourly Remaining Length of Stay. Index files were updated to include the new modules accordingly.

pyhealth.tasks.hourly_los

Task Definition

•	Predict remaining LoS at every hour
•	Predictions start after first 5 hours
•	Continuous regression task

Motivation

•	Mimics real-world ICU monitoring
•	Enables dynamic prediction updates

3) Ablation Study/ Example Usage

We implemented scripts for runnning the pipeline end to end with support for different experiemental setups or ablations.

examples/eicu_hourly_los_tpc.py : This provides an end-to-end script for reproducing and evaluating pipeline on EICU dataset.
examples/mimic4_hourly_los_tpc.py : This provides an end-to-end script for reproducing and evaluating pipeline on MIMIC-IV dataset.
examples/run_dual_dataset_tpc.py : This utility scripts runs the pipeline on both datasets and produces a combined report.

4) Test Cases

We implemented fast performing test cases for our Model and Task contribution using Sythentic Data.

tests/models/test_tpc.py
tests/tasks/test_hourly_los.py

Experimental Setup and Findings

  1. Ablations to include/exclude domain specific engineering (skip connections, decay indicators, etc)

image
2) Comparison across using combined temporal and pointwise convolutions vs using either architecture alone.
image
3) Feature independant (no weight-sharing) vs weight-shared temporal convolutions.
image
4) Evaluating MSLE loss vs MSE loss for skewed LoS target regression.
image
## Testing model with varying hyperparameters.

We varied key optimization and architectural hyperparameters (e.g. learning rate, dropout rate, etc) while keeping preprocessing and data splits fixed.

image

File Structure

.
├── pyhealth/models/tpc.py
├── pyhealth/tasks/hourly_los.py
├── pyhealth/datasets/configs/eicu_tpc.yaml
├── pyhealth/datasets/configs/mimic4_ehr_tpc.yaml
├── examples/eicu_hourly_los_tpc.py
├── examples/mimic4_hourly_los_tpc.py
├── examples/run_dual_dataset_tpc.py
├── tests/models/test_tpc.py
├── tests/tasks/test_hourly_los.py
├── docs/api/models.rst
├── docs/api/models/pyhealth.models.tpc.rst
├── docs/api/tasks.rst
├── docs/api/tasks/pyhealth.tasks.hourly_los.rst
└── README_TPC_LOS.md

Setup

  1. Clone the repository.
  2. Create and activate a python virtual environment.
  3. Install project dependencies.
  4. Set dataset paths with environment variables for the example scripts.

Quick Start (Synthetic Data)

eICU example

EICU_ROOT=/path/to/synthetic/eicu/data \
PYTHONPATH=. python3 examples/eicu_hourly_los_tpc.py \
  --epochs 1 \
  --batch_size 2 \
  --max_samples 8 \
  --model_variant full \
  --loss msle \
  --num_workers 1

MIMIC-IV example

MIMIC4_ROOT=/path/to/synthetic/mimic4/data \
PYTHONPATH=. python3 examples/mimic4_hourly_los_tpc.py \
  --epochs 1 \
  --batch_size 2 \
  --max_samples 8 \
  --loss msle \
  --num_workers 1

Combined dual-dataset run

EICU_ROOT=/path/to/synthetic/eicu/data \
MIMIC4_ROOT=/path/to/synthetic/mimic4/data \
PYTHONPATH=. python3 examples/run_dual_dataset_tpc.py \
  --eicu_cache_dir /path/to/eicu/cache/location
  --mimic_cache_dir /path/to/mimic/cache/location
  --eicu_max_samples 8 \
  --mimic_max_samples 8 \
  --eicu_epochs 1 \
  --mimic_epochs 1 \
  --model_variant full \
  --loss msle \
  --num_workers 1

Notes on Real Data

For full eICU or MIMIC-IV experiments, point EICU_ROOT or MIMIC4_ROOT to the real dataset locations and increase settings such as --epochs, --batch_size, and --max_samples as needed.

Tests

Run the project-specific tests with:

python3 -m pytest tests/models/test_tpc.py tests/tasks/test_hourly_los.py -q

Documentation

API documentation entries were added for:

  • pyhealth.models.tpc
  • pyhealth.tasks.hourly_los

Output

The example scripts print compact summary lines for quick validation:

  • ABLATION_SUMMARY for eICU
  • MIMIC_SUMMARY for MIMIC-IV

The dual-dataset runner parses both and prints a combined summary table.

Environment

This project is designed to run within the PyHealth environment.

Recommended setup:

  • Python 3.12
  • pyhealth (>= 2.0.0)
  • torch
  • standard scientific Python stack (numpy, pandas)

Install PyHealth and dependencies following the main repository instructions.

medukonis and others added 25 commits April 19, 2026 13:54
Summary:
- Added end-to-end pipeline for reproducing TPC-style LoS prediction using PyHealth
- Verified data loading, task transformation, and model training loop

New files:
- pyhealth/models/tpc.py
  - Implements Temporal Pointwise Convolution (TPC) model as BaseModel subclass
  - Includes temporal + pointwise convolution blocks and regression head

- pyhealth/tasks/hourly_los.py
  - Custom BaseTask implementation for hourly remaining length-of-stay prediction
  - Uses eICU patient + lab event partitions
  - Converts labresultoffset (minutes) → hourly time bins
  - Generates causal samples (t -> remaining LoS)

- examples/eicu_hourly_los_tpc.py
  - End-to-end example script
  - Loads eICU dataset (dev mode)
  - Applies HourlyLOSEICU task
  - Wraps samples into PyTorch Dataset + DataLoader
  - Trains TPC model with MSLE loss

Key design decisions:
- Used event_type_partitions + get_events() API (no visit abstraction in this branch)
- Treated each Patient object as a stay-level sequence
- Used labresultoffset instead of timestamp (timestamp is synthetic)
- Started with single feature ('-basos') for pipeline validation

Current status:
- Task successfully generates ~28k samples from 1000 patients (dev mode)
- Training loop runs end-to-end
- Loss decreases across epochs (sanity check passed)

Limitations / TODO:
- Only 1 lab feature currently used
- No forward-fill or masking yet
- No static features
- Not yet aligned with full paper feature set
- TPC architecture is simplified vs paper

Next steps:
- Expand to multiple lab features
- Add forward-fill + missingness indicators
- Incorporate additional tables (if supported)
- Align model architecture with original paper

Notes:
- Requires running with PYTHONPATH=. to use local PyHealth modifications
- i.e PYTHONPATH=. python3 examples/eicu_hourly_los_tpc.py
…al split, channel ablations, and categorical static encoding
…riments

- Implement TPC model with temporal + pointwise branches
- Add configurable ablations (temporal_only, pointwise_only, shared_temporal, no_skip_connections)
- Support MSLE and MSE loss options
- Add synthetic smoke test and full eICU example pipeline
- Add unit tests for model forward pass and hourly LoS task
- Conduct hyperparameter sensitivity experiments (Extension 1)

This commit enables full hypothesis evaluation (H1–H4) and Extension 1.
- Included Paper link
- Included Ablations and model comparison details from our deck
- Included the index file changes and updated file structure with the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants